//
//  SearchView.swift
//  GreenDeal
//
//  Created by Moennig Q on 24/2/2023.
//

import UIKit
import SnapKit
class BaseSearchView: View {
    let searchTextField: DIYTextField = DIYTextField()
    lazy var tableView: TableView = {
        let view = TableView.init(frame: .zero, style: .plain)
        view.backgroundColor = .white
        view.separatorStyle = UITableViewCell.SeparatorStyle.none
        view.estimatedRowHeight = 64
        view.rowHeight = UITableView.automaticDimension
        view.estimatedSectionHeaderHeight = 0
        view.estimatedSectionFooterHeight = 0
        view.showsVerticalScrollIndicator = false
        view.backgroundColor = .white
        return view
    }()
    let cancelBtn = BaseButton()
    //
    override func setUpView() {
        self.backgroundColor = UIColor(hexStr: Constant.ThemeColorHexStr)
        //1. search text field
        searchTextField.returnKeyType = UIReturnKeyType.search
        searchTextField.showLeftImageView("edit_address_search_icon")
        searchTextField.placeholder = R.string.localizable.search()
        self.addSubview(searchTextField)
        searchTextField.snp.makeConstraints { (make) in
            make.left.equalTo(16)
            make.top.equalTo(self.safeAreaLayoutGuide.snp.top).offset(20)
            make.width.greaterThanOrEqualTo(0)
            make.height.equalTo(DIYTextField.height)
            
        }
        //1.1 cancel btn
        cancelBtn.setTitle("Cancel", for: .normal)
        cancelBtn.setTitleColor(UIColor.white, for: .normal)
        cancelBtn.setFont(R.font.interMedium(size: 15))
        self.addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { make in
            make.left.equalTo(searchTextField.snp.right).offset(10)
            make.right.equalTo(-16)
            make.centerY.equalTo(searchTextField)
            make.height.equalTo(40)
            make.width.greaterThanOrEqualTo(0)
        }
        //tableview
        self.addSubview(tableView)
        tableView.snp.makeConstraints { make in
            make.top.equalTo(searchTextField.snp.bottom).offset(20)
            make.left.right.equalToSuperview()
            make.bottom.equalToSuperview()
        }
        searchTextField.becomeFirstResponder()
    }
}
